package org.yn.emp.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.yn.base.service.impl.BaseServiceImpl;
import org.yn.base.until.PageInfo;
import org.yn.emp.EmployeeDTO;
import org.yn.emp.domain.Employee;
import org.yn.emp.mapper.EmployeeMapper;
import org.yn.emp.service.IEmployeeService;
import org.yn.query.EmployeeQuery;

import java.io.Serializable;
import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
//    @Override
//    public List<Employee> selectAll() {
//        return employeeMapper.selectAll();
//    }
//
//    @Override
//    public Employee selectById(Long id) {
//
//        return employeeMapper.selectById(id);
//    }
//
//    @Transactional
//    @Override
//    public void insert(Employee employee) {
//        employeeMapper.insert(employee);
//    }
//
//    @Transactional
//    @Override
//    public void update(Employee employee) {
//        employeeMapper.update(employee);
//    }
//
//    @Transactional
//    @Override
//    public void delete(Long id) {
//        employeeMapper.delete(id);
////        System.out.println(1/0);
//    }



    @Override
    public Employee selectByName(String username) {
        return employeeMapper.selectByName(username);
    }


    // 分页查询
    @Override
    public PageInfo<Employee> queryPage(EmployeeQuery employeeQuery) {
        Integer total =employeeMapper.countTotal(employeeQuery);
        if (total==0){
            return new PageInfo<Employee>();//返回一个空的
        }
        //查询分页数据
        List<Employee> list= employeeMapper.queryPage(employeeQuery);

        return new PageInfo<Employee>(total, list);
    }

    @Override
    public void insertByEmployeeId(EmployeeDTO employeeDTO) {
        //删除该角色的权限
        employeeMapper.deleteByEmployeeId(employeeDTO.getEmployeeId());
        //保存新的
        employeeMapper.insertByEmployeeId(employeeDTO);
    }

    @Override
    public List<Long> selectByEmployeeId(Long id) {
        return employeeMapper.selectByEmployeeId(id);
    }

    @Override
    public List<String> queryPermissionByUserId(Long id) {
        return employeeMapper. queryPermissionByUserId(id);
    }


}
